﻿using System.Windows;
using NtpChat.Client.ViewModel;
using GalaSoft.MvvmLight.Messaging;

namespace NtpChat.Client
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Closing += (s, e) => ViewModelLocator.Cleanup();
            Messenger.Default.Register<GenericMessage<ConversationViewModel>>(this, HandleConversation);
        }

        public void HandleConversation(GenericMessage<ConversationViewModel> message)
        {
            if (message.Sender.GetType() == typeof(MainViewModel))
            {
                if (message.Content.GetType() == typeof(ConversationViewModel))
                {
                    ConversationView view = new ConversationView();
                    view.DataContext = message.Content;
                    view.Show();
                }
            }
        }

        private void MainView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
        	//Messenger.Default.Send<GenericMessage<Window>>(new GenericMessage<Window>(this,typeof(MainViewModel),this));
        }
    }
}
